package com.waitingsnow.core.display.control
{
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;

/**
 * 
 * @author waitingsnow
 * $Id: ToolTip.as 2 2012-05-17 10:10:03Z cgslendy@gmail.com $
 */
public class ToolTip extends Sprite
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	/**
	 * Constructs a new <code>ToolTip</code> instance.
	 * 
	 */
	public function ToolTip()
	{
		initDisplay();
	}
	
	//==========================================================================
	//  Variables
	//==========================================================================
	private var targetObj:InteractiveObject;
	private var tf:TextField;
	
	private var tipContent:String;
	private var tipTitle:String;
	
	//==========================================================================
	//  Properties
	//==========================================================================
	/**
	 * 提示框宽度
	 */	
	private var _tipWidth:int = 200;
	
	/**
	 * 文本和边距间隔
	 */	
	private var _tipGap:int = 5;
	
	/**
	 * 背景渐变色
	 */	
	private var _bgColor:Array = [0xFFFFFF, 0xe4e5f0];
	
	/**
	 * 背景透明度
	 */	
	private var _bgAlpha:Number = 1;
	
	/**
	 * 是否有边框
	 */	
	private var _border:Boolean;
	
	/**
	 * 边框颜色
	 */	
	private var _borderColor:Number;
	
	/**
	 * 边框大小
	 */	
	private var _borderSize:int = 1;
	
	/**
	 * 标题格式
	 */	
	private var _titleTft:TextFormat = new TextFormat("_sans", 14, 0x818181, true);
	
	/**
	 * 内容格式
	 */	
	private var _contentTft:TextFormat = new TextFormat("_sans", 12, 0x575757);
	
	/**
	 * 延迟时间
	 */	
	private var _delayTime:int = 0;
	
	//==========================================================================
	//  Methods
	//==========================================================================
	private function initDisplay():void
	{
		mouseEnabled = mouseChildren = false;
	}
	
	public function show(target:InteractiveObject, tipContent:String, 
						 tipTitle:String = null):void
	{
		this.targetObj = target;
		this.tipContent = tipContent;
		this.tipTitle = tipTitle;
		target.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
		target.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
		target.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
	}
	
	private function createBg():void
	{
		
	}
	
	private function initTf():void
	{
		!tf && (tf = new TextField());
		tf.htmlText = tipTitle;
	}
	
	private function showTf():void
	{
		!tf && initTf();
		tf && !tf.parent && addChild(tf);
		
	}
	
	//==========================================================================
	//  Event Handlers
	//==========================================================================
	private function rollOverHandler(event:MouseEvent):void
	{
		showTf();
	}
	
	private function rollOutHandler(event:MouseEvent):void
	{
		
	}
	
	private function mouseMoveHandler(event:MouseEvent):void
	{
		showTf();
	}
}
}